using System;
using System.Collections;
using BitMango;
using TMPro;
using UnityEngine;

public class StarterInfo : MonoBehaviour
{
	private void OnEnable()
	{
		this.btn.SetActive(false);
		base.StartCoroutine(this.CoStarterSystem());
	}

	private void OnDisable()
	{
		base.StopCoroutine(this.CoStarterSystem());
	}

	private IEnumerator CoStarterSystem()
	{
		while (!Wallet.IsValid())
		{
			yield return new WaitForEndOfFrame();
		}
		if (this.IsStarterShow())
		{
			this.btn.SetActive(true);
			for (;;)
			{
				DateTime installed = DateTime.UtcNow;
				if (PlayerPrefs.HasKey("installed"))
				{
					installed = DateTime.Parse(PlayerPrefs.GetString("installed"));
				}
				DateTime afterThreeDay = installed.AddDays(3.0);
				if (!(afterThreeDay > DateTime.UtcNow))
				{
					break;
				}
				TimeSpan timeSpan = afterThreeDay - DateTime.UtcNow;
				this.starterTime.text = string.Format("{0:00}:{1:00}:{2:00}", (int)timeSpan.TotalHours, timeSpan.Minutes, timeSpan.Seconds);
				if (this.OnChangeTime != null)
				{
					this.OnChangeTime(this.starterTime.text);
				}
				yield return new WaitForSeconds(1f);
			}
			this.btn.SetActive(false);
			yield break;
		}
		yield break;
		yield break;
	}

	private bool IsStarterShow()
	{
		DateTime dateTime = DateTime.UtcNow;
		if (PlayerPrefs.HasKey("installed"))
		{
			dateTime = DateTime.Parse(PlayerPrefs.GetString("installed"));
		}
		DateTime t = dateTime.AddDays(3.0);
		return t > DateTime.UtcNow && Wallet.GetItemCount("unlockall") <= 0;
	}

	public string GetStarterTime()
	{
		return this.starterTime.text;
	}

	private void OnClickStarterPack()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		DWATTHelper.logEvent("StarterPack", new object[]
		{
			"Enter"
		});
		Scene.QueuePopup("StarterPackPopup", this, delegate(object isSuccess)
		{
			if ((bool)isSuccess)
			{
				base.StopCoroutine(this.CoStarterSystem());
				this.btn.SetActive(false);
				SyncPackage.Sync();
			}
		});
	}

	public void ShowStarterPack()
	{
		//if (this.IsStarterShow())
		//{
		//	this.OnClickStarterPack();
		//}
	}

	public Action<string> OnChangeTime;

	public GameObject btn;

	public TextMeshPro starterTime;
}
